from pyb import LED # type: ignore

class Light:
    def __init__(self):
        LED(4).off()
        self.state = False

    """打开灯"""
    def on(self):
        if(self.state == False):
            LED(4).on()
            self.state = True

    """关闭灯"""
    def off(self):
        if(self.state == True):
            LED(4).off()
            self.state = False


''' 示例
# Light示例 - By: LUCKBACK - Mon Sep 2 2024

import sensor, image, time
from Light import Light

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_auto_whitebal(True)
sensor.skip_frames(time = 2000)

Light = Light()

clock = time.clock()

now_time = 0
old_time = 0

while(True):
    clock.tick()
    img = sensor.snapshot()
    now_time = time.ticks_ms()
    if(now_time - old_time>1000):
        Light.on()
    if(now_time - old_time>2000):
        Light.off()
        old_time = now_time
'''